package boot.spring.service.impl;

import boot.spring.entity.Student;
import boot.spring.mapper.StudentMapper;
import boot.spring.service.AllTheStudentsService;
import boot.spring.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AllTheStudentsServiceImpl implements AllTheStudentsService {
    Result r=new Result();

    @Autowired/*注入学生表的持久层*/
    private StudentMapper studentMapper;


    /*分页多条件获取学生信息*/
    @Override
    public Result ListStuSerPageLimitAll(Integer page,Integer limit,String stuname,String ifPay,String qq,String sex) {
        Map<String,Object> map=new HashMap<>();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("stuname",stuname);
        map.put("ifPay",ifPay);
        map.put("qq",qq);
        map.put("sex",sex);
        List<Student> liststu=studentMapper.ListStuMapPageLimitAll(map);
        Integer count=studentMapper.GetCount(map);
        if (liststu.size()>0){
            r=new Result(0,"请求成功",count,liststu);
        }else{
            r=new Result(1,"请求失败");
        }
        return r;
    }
    /*编辑学生信息*/
    @Override
    public Result GetStuSerUp(Student stuup) {
        Integer getstuup=studentMapper.GetStuMapUp(stuup);
        if (getstuup>0){
            r=new Result(0,"修改成功");
        }else{
            r=new Result(1,"修改失败");
        }
        return r;
    }
    /*删除学生信息*/
    @Override
    public Result GetStuSerDel(Integer stuid) {
        Integer getstudel=studentMapper.GetStuMapDel(stuid);
        if (getstudel>0){
            r=new Result(0,"删除成功");
        }else{
            r=new Result(1,"删除失败");
        }
        return r;
    }
}
